(function($){
	$.fn.map={};
	$.fn.map.initial=function(){
		mapInitail();
		getData();
	};
	var map;
	var point;
	var mapInitail=function(){
		map = new BMap.Map("allmap",{minZoom:12,maxZoom:16});
		point = new BMap.Point(118.8, 32.0625);
		map.centerAndZoom(point, 11);	
		map.enableScrollWheelZoom();
		
		
	};
	var addClickHandler=function(content,marker){
		marker.addEventListener("click",function(e){
			var infoWindow = new BMapLib.SearchInfoWindow(map,content,
				    {
				  //    title: title, //标题
						width: 110, //宽度
						height: 100, //高度
						panel : "panel", //检索结果面板
						enableAutoPan : true, //自动平移
						enableSendToPhone: true, //是否显示发送到手机按钮
						searchTypes :[
							BMAPLIB_TAB_SEARCH,   //周边检索
							BMAPLIB_TAB_TO_HERE,  //到这里去
							BMAPLIB_TAB_FROM_HERE //从这里出发
						]
						}
					);
			infoWindow.open(marker); 
		})
	};
	var getData=function(){
		$.ajax({
			url:'device/getAll',
			dataType:'json',
			success:function(data){
				if (data['status']==1001) {
					data=data.body;
					for(var i=0;i<data.length;i++){
						var marker = new BMap.Marker(new BMap.Point(data[i]['longitude'], data[i]['latitude']));
						map.addOverlay(marker);
						addClickHandler(data[i]['name'],marker);
					}
				}
			}
		});
	};
})(jQuery);